// index.ts

import { HOST_URL } from "../../config/index"
// import { marked } from './marked.esm'
const { marked } = require('./../../utils/marked.umd')
// const app = getApp();

// 获取应用实例
// const app = getApp<IAppOption>()

Page({
  data: {
    top: 0,
    question: '',
    article: '',
    book: '',
  },
  option: {} as any,
  onLoad(option) {
    console.log(option)
    this.option = option
    this.setData({
      question: option.wenti,
    })
    const { statusBarHeight } = wx.getWindowInfo()
    this.setData({
      top: statusBarHeight,
    })
    this.initData()
  },
  goback() {
    wx.navigateBack()
  },
  initData() {
    wx.showLoading({
      title: 'ai正在思考中',
      mask: true,
    })
    wx.request({
      url: HOST_URL + 'book/ai',
      method: 'GET',
      data: {
        id: this.option.id,
        wenti: this.option.wenti,
      },
      success: (res: any) => {
        wx.hideLoading()
        
        const markdownText = marked.parse(res.data.data.huida);
        console.log(markdownText)

        this.setData({
          article: markdownText,
          book: res.data.data.book.original,
        })
      },
    })
  }
    
})
